/*
 * LcodeConvertEngine.cpp
 *
 *  Created on: 2009-8-23
 *      Author: ws
 */

#include <list>
#include<iostream>
#include <algorithm>

#include<Lcode/l_code.h>

#include"LcodeBlockImpl.hpp"
#include"../cg/Region.hpp"
#include"../cg/Operation.hpp"
#include"../cg/FunctionUnit.hpp"
#include"../cg/RegionBuilder.hpp"
#include"LcodeConvertEngine.hpp"
using namespace std;
LcodeConvertEngine::LcodeConvertEngine()
{

}

FunctionUnit * LcodeConvertEngine::convert(L_Func * fn)
{
	//first_build all regions
	L_Cb * cb = fn->first_cb;
	RegionBuilder builder ;
	Region * entry = NULL;
	Region * exit = NULL;
	for(cb  = cb->next_cb; cb != NULL; cb = cb->next_cb)
	{
		bk = new LcodeBlockImpl(cb);
		Region * t = builder.build_new_region(bk);
		if( t->get_type() == EXIT_BT)
			exit = t;
	}
	return new  FunctionUnit(std::string(fn->name), entry, exit);
}

LcodeConvertEngine::~LcodeConvertEngine()
{
	
}

